/*
 * AboutWindow.java
 *
 * Created on __DATE__, __TIME__
 */

package Windows;

import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;

import DBUtil.CNN;
import Tools.IMG;
import Tools.JLabelStyle;
import Windows.ShowWindows.ShowWindow;

/**
 * 
 * @author __USER__
 */
public class AboutWindow extends ShowWindow implements MouseListener {
	private static AboutWindow aw;

	public static AboutWindow getAboutWindow() {
		if (aw == null) {
			aw = new AboutWindow();
		}
		return aw;
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				new AboutWindow().setVisible(true);
			}
		});
	}

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JLabel jLShare;

	private javax.swing.JLabel jLabel1;

	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JLabel jLabel7;
	private javax.swing.JPanel jPAbout;
	/** Creates new form AboutWindow */
	private AboutWindow() {

		jPAbout = new PicPanel(IMG.about2, IMG.about1);
		this.setContentPane(new PicPanel(IMG.aboutBG));

		initComponents();

		Tools.ToCenter.ToCenter(this);

		this.addMouseListener(this);

		this.addWindowListener(super.getOpacityWindowsListener());

//		jLabel3.addMouseListener(JLabelStyle.getStyleListener());
//		jLabel4.addMouseListener(JLabelStyle.getStyleListener());
//		jLabel5.addMouseListener(JLabelStyle.getStyleListener());
		jLabel7.addMouseListener(JLabelStyle.getStyleListener());

//		MouseListener ml = ((PicPanel) jPAbout).getMouseListener();
//		jLabel3.addMouseListener(ml);
//		jLabel4.addMouseListener(ml);
//		jLabel5.addMouseListener(ml);
		jLabel7.addMouseListener(this);

		jLShare.addMouseListener(this);
		jLabel1.addMouseListener(this);

		jLShare.setIcon(IMG.ii);
		jLabel1.setIcon(IMG.logo2);

	}
	public void doFinish() {
		jLabel6.setVisible(false);
		jLabel2.setVisible(false);
	}

	// End of variables declaration//GEN-END:variables

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jLShare = new javax.swing.JLabel();

		jLabel6 = new javax.swing.JLabel();
		jLabel5 = new javax.swing.JLabel();
		jLabel4 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jLabel7 = new javax.swing.JLabel();
		jLabel1 = new javax.swing.JLabel();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		jLabel6.setForeground(new java.awt.Color(255, 255, 255));
		jLabel6.setText("连接服务器...");

		jLabel5.setForeground(new java.awt.Color(255, 255, 255));
		jLabel5.setText("");

		jLabel4.setForeground(new java.awt.Color(255, 255, 255));
		jLabel4.setText("");

		jLabel3.setForeground(new java.awt.Color(255, 255, 255));
		jLabel3.setText("");

		jLabel2.setForeground(new java.awt.Color(255, 255, 255));
		jLabel2.setText("正在启动:");

		jLabel7.setForeground(new java.awt.Color(255, 255, 255));
		jLabel7.setText(CNN.getConfig().GetPathValue("User:about").toString());
		jLabel7.setFont(new Font("Default", 0, 12));
		javax.swing.GroupLayout jPAboutLayout = new javax.swing.GroupLayout(jPAbout);
		jPAbout.setLayout(jPAboutLayout);
		jPAboutLayout.setHorizontalGroup(jPAboutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPAboutLayout.createSequentialGroup().addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jLabel7).addGap(30, 30, 30).addComponent(jLabel2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
//										.addComponent(jLabel3)
//										.addPreferredGap(
//												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
//										.addComponent(jLabel4)
//										.addPreferredGap(
//												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
//										.addComponent(jLabel5)
//										.addPreferredGap(
//												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				.addComponent(jLabel6).addContainerGap()));
		jPAboutLayout.setVerticalGroup(jPAboutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPAboutLayout.createSequentialGroup().addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addGroup(jPAboutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel6)
//														.addComponent(
//																jLabel5,
//																javax.swing.GroupLayout.PREFERRED_SIZE,
//																15,
//																javax.swing.GroupLayout.PREFERRED_SIZE)
//														.addComponent(jLabel4)
//														.addComponent(jLabel3)
				.addComponent(jLabel7).addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap()));

		jLabel1.setIcon(IMG.logo); // 修改一般情况下的图标

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap(50, Short.MAX_VALUE).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(jLShare).addGap(18, 18, 18).addComponent(jLabel1).addGap(192, 192, 192)).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(jPAbout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(47, 47, 47)))));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addGroup(layout.createSequentialGroup().addGap(84, 84, 84).addComponent(jLabel1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLShare).addGap(18, 18, 18))).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPAbout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap()));

		pack();
	}// </editor-fold>
		// GEN-END:initComponents

	@Override
	public void mouseClicked(MouseEvent me) {
		if (!isVisible()) {
			ShowWindow.PalyWindow(getAboutWindow());
		} else if (MainWindows.getInstance().isVisible()) {
			ShowWindow.stopWindow(getAboutWindow());
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		Object obj = e.getSource();
		if (obj.equals(jLShare)) {
			jLShare.setIcon(IMG.ii2);
		} else if (obj.equals(jLabel1)) {
			jLabel1.setIcon(IMG.logo2);
		}

	}

	@Override
	public void mouseExited(MouseEvent e) {

		Object obj = e.getSource();
		if (obj.equals(jLShare)) {
			jLShare.setIcon(IMG.ii);
		} else if (obj.equals(jLabel1)) {
			jLabel1.setIcon(IMG.logo2);
		}
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		if (arg0.getSource() == jLabel7) {
			String str = "cmd /c start iexplore " + CNN.getConfig().GetPathValue("User:WebSite").toString();
			try {
				Runtime.getRuntime().exec(str);
			} catch (IOException e1) {
				e1.printStackTrace();
			}

		}

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {

	}

	public void setMessage(String msg) {
		jLabel6.setForeground(new java.awt.Color(0, 255, 0));
		jLabel6.setText(msg);
	}

	public void setMessageError(String msg) {
		jLabel6.setForeground(new java.awt.Color(255, 0, 0));
		jLabel6.setText(msg);
	}
}